/**
 * Created by Brant on 2016/12/28.
 * 案件动态
 */
module.exports = function ($rootScope, $scope, $cookies, caseBarDetailDongService,httpservice,paginationService) {
  $rootScope.showCaseDiv = false;
    /*获取点击的案件的id*/
    $scope.caseId = $cookies.get('caseAppId');
    /*初始页*/
    $scope.pageNum = 1;
    /*每页显示的条数*/
    $scope.pageSize = 10;

    $scope.httpServiceImg = httpservice.murlWebHttp;
    $scope.pageSetting3 = paginationService.getDefaultPageSetting();

    /**
     * 初始化
     */
    $scope.init = function () {
        $scope.caseMessage();
        /*用于固定导航条*/
        sessionStorage.navNum = 6;
    };

    /**
     * 案件动态
     */
    $scope.msgData = [];
    $scope.caseMessage = function () {
        caseBarDetailDongService.caseMessage($scope.caseId, $scope.pageSetting3.pageNo, $scope.pageSetting3.pageSize).then(function (response) {
            /*请求成功*/
            if (response.code == 1) {
                /*设置其他页码颜色*/
                $('.select').css('color', '#666');
                $scope.msgData = $scope.msgData.concat(response.data);

                $scope.pageSetting3.totalItems = response.totalCount;

              // $scope.msgData.push($scope.msgData);

                $scope.totalPage = response.totalPage;//总页数
                $scope.totalCount = response.totalCount;//总条数
                $scope.beginPage = response.beginPage;//开始页
                $scope.endPage = response.endPage;//结束页
                // for (var i=0;i<$scope.msgData.length;i++){
                //     $scope.msgData[i].operationitemname = $scope.msgData[i].operationitemname.replace(/<.*?>/ig,"");
                // }


                /*如果数据为空，怎隐藏底部页码*/
                if ($scope.totalCount < 1) {
                    $('#bottom-page').hide();
                    $('#id-data-null').show();
                }
                /*声明一个数组显示页数*/
                $scope.arrPage = new Array();
                for (var j = 0; j < $scope.endPage; j++) {
                    $scope.arrPage[j] = j + 1;
                }
                // /*日期格式化*/
                // for (var i = 0; i < response.data.length; i++) {
                //     $scope.msgData[i].createddate = new Date(response.data[i].createddate).pattern("yyyy-MM-dd hh:mm:ss");
                // }
                /*设置当前页码颜色*/
                setTimeout(function () {
                    $('.select' + $scope.pageNum).css('color', 'red');
                }, 50);
            } else {
                /*网络请求出错*/
                $rootScope.fadeShow = false;
                $('#bottom-page').hide();
                $('#id-data-net-err').show();
            }
        }, function (response) {
            $rootScope.loadingShow = false;
            $rootScope.fadeShow = false;
            $('#bottom-page').hide();
            $('#id-data-net-err').show();
            console.error('caseMessage error', response.status, response.statusText);
        });

    };

    /**
     * 案件动态点击改变页数
     * @param currentPage
     */
    $scope.changePage = function (currentPage) {
        if (currentPage == undefined) {
            currentPage = 1;
        }
        if (currentPage <= $scope.totalPage && currentPage > 0) {
            $scope.caseMessage(currentPage);
            $scope.pageNum = currentPage;
        }else {
            console.log('列表页码越界!');
        }

    };

    /**
     * 名字如果为三位数，截取后两位
     */
    $("#edit-name").change(function () {
        var name = $("#edit-name").val();
        if (isChinese(name)) {
            var nameSub = name.substr(name.length - 2);
            $(".position_relative").html(nameSub);
        }else{
            $(".position_relative").html(name);
        }
    });

    /**
     * 判断是否为中文
     * @param temp
     * @returns {boolean}
     */
    function isChinese(temp) {
        var re = /[^\u4e00-\u9fa5]/;
        if (re.test(temp)) return false;
        return true;
    }


    $scope.init();



};
